<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="base.js"></script>
        <script>
            onload = function() {
                var aLi = document.getElementsByTagName("li");
                for (var i=0; i<aLi.length; i++) {
                    var oA = aLi[i].getElementsByTagName("a")[0]; //a节点
                    oA.onclick = function() {
                        var aSpan = this.parentNode.getElementsByTagName("span");
                        var name = aSpan[0].innerHTML;
                        var price = aSpan[1].innerHTML;

                        var d = new Date();
                        d.setDate(d.getDate()+7); //7天后的日期
                        var cookieText = setCookie(name, price, d);

                        //json
                        /*
                          "goods="+ "{商品1:$45, 商品2:$46, 商品3:$47,... }"
                         */
                    }

                }
            }
        </script>
    </head>
    <body>
        <ul>
            <li><span>商品1</span> <span>$45</span> <a href="#">加入购物车</a> </li>
            <li><span>商品2</span> <span>$46</span> <a href="#">加入购物车</a> </li>
            <li><span>商品3</span> <span>$47</span> <a href="#">加入购物车</a> </li>
            <li><span>商品4</span> <span>$48</span> <a href="#">加入购物车</a> </li>
            <li><span>商品5</span> <span>$49</span> <a href="#">加入购物车</a> </li>
            <li><span>商品6</span> <span>$50</span> <a href="#">加入购物车</a> </li>
        </ul>
        <a href="3_练习1_cart.html">查看购物车</a>

    </body>
</html>